using Identity.Domain.Aggregates;
using Identity.Domain.ValueObjects;
using Identity.Infrastructure.Configurations;
using Identity.Infrastructure.Entities;
using Identity.Infrastructure.Persistence.Configurations;
using Identity.Infrastructure.Persistence.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : IdentityDbContext<
    ApplicationUser,
    ApplicationRole,
    Guid,
    IdentityUserClaim<Guid>,
    UserRoleEntity, // 这里替代默认 IdentityUserRole<Guid>
    IdentityUserLogin<Guid>,
    IdentityRoleClaim<Guid>,
    IdentityUserToken<Guid>>
{

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options) { }

    public DbSet<Permission> Permissions => Set<Permission>();
    public DbSet<RolePermissionEntity> RolePermissions => Set<RolePermissionEntity>();
    public new DbSet<UserRoleEntity> UserRoles => Set<UserRoleEntity>();
    public DbSet<ApiPermissionBinding> ApiPermissionBindings => Set<ApiPermissionBinding>();
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        // OpenIddict schema
        builder.UseOpenIddict();
        // 配置实体
        builder.ApplyConfiguration(new UserRoleConfiguration());
        builder.ApplyConfiguration(new RolePermissionConfiguration());
        builder.ApplyConfiguration(new PermissionConfiguration());
        builder.ApplyConfiguration(new ApiPermissionBindingConfiguration());

        builder.Entity<PermissionScope>()
        .HasNoKey();

    }
}